package com.liyunc.socket.callback.utils;

import java.util.HashMap;
import java.util.Map;

public class ClientBase {

    String user = "";

    public interface CallBack {
        void callback(String res);
    }

    public void request(String data, CallBack callBack, String... id) {
        setData(data);
        callBack.callback(user);
    }

    private void setData(String data) {
        //模拟后端查询数据库
        if (data.contains("username=tom") && data.contains("password=tom123")) {
            Map<String, String> address = new HashMap<>();
            address.put("street", "华府大道");
            address.put("city", "成都市");
            address.put("country", "中国");

            Map<Object, Object> userInfo = new HashMap<>();
            userInfo.put("name", "tom");
            userInfo.put("sex", "男");
            userInfo.put("age", "30");
            userInfo.put("address", address);
            userInfo.put("role", "user");

            user = userInfo.toString();
        } else {
            user = "[查询数据为空]";
        }
    }
}
